package Creational.Prototype.prototypeManager.student;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class PrototypeManager
{
    //定义一个哈希表，存储原型对象
    private Map<String,Object> ht;

    private static PrototypeManager pm;

    private PrototypeManager(){
        ht=new ConcurrentHashMap<>();
    }

    //    往哈希表里存值
    public void addPrototype(String key,Object obj)
    {
        ht.put(key,obj);
    }

    //    往哈希表里删值
    public Object removePrototype(String key)
    {
        return ht.remove(key);
    }

    //    取值
    public Object getPrototype(String key)
    {
        return ht.get(key);
    }
    //    新建prototypeManger对象  饿汉 单例模式
    public synchronized static PrototypeManager getInstance()
    {
        if(pm==null){
            synchronized (PrototypeManager.class){
                if(pm==null){
                    pm = new PrototypeManager();
                }
            }
        }
        return pm;
    }
}
